<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <link rel="stylesheet" href="../css/bootstarp.min.css">
    <title>表单域值绑定</title>
</head>
<body>

  <div id="root">
    <form @submit.prevent="onSubmit">
       用户名：<input type="text" v-model="userInfo.username" class="form-control"> <br>
       密码：<input type="password" v-model="userInfo.password" class="form-control"> <br>
       性别：男<input type="radio" v-model="userInfo.sex" name="sex" value="male"> 
                         女<input type="radio" v-model="userInfo.sex" name="sex" value="woman"> <br>
       年龄：<input type="text" v-model.number="userInfo.age" class="form-control"> <br>
       爱好：吃饭<input type="checkbox" v-model="userInfo.hobby" value="eat"> 
            睡觉<input type="checkbox" v-model="userInfo.hobby" value="sleep"> 
            打游戏<input type="checkbox" v-model="userInfo.hobby" value="play"><br> 
       城市：<select v-model="userInfo.city" class="form-control">
             <option value="null" disabled>--请选择居住城市--</option>
             <option value="beijing">北京</option>
             <option value="shanghai">上海</option>
             <option value="hangzhou">杭州</option>
            </select> <br>
        个人描述：<textarea v-model="userInfo.description" class="form-control"></textarea><br>
        <input type="checkbox" v-model="confirmed">我已阅读并同意 <a href="#">《用户须知》</a><br>     
        <button :disabled="!confirmed" class="btn btn-primary btn-group-lg">提交</button>
    </form>
  </div>  

<script>
    new Vue({
     el:'#root',
    data:{
      confirmed:false,
      userInfo:{
        username:'',
        password:'',
        sex:'',
        age:null,
        hobby:[],
        city:'',
        description:''
      }  
     },
     methods: {
       onSubmit(){
          alert(JSON.stringify(this.userInfo))
       } 
     }
    })
</script>    
</body>
</html>